package com.huazi.user.registration.dao.imp;

import com.huazi.user.registration.dao.Docator_Info;
import com.huazi.user.registration.entity.Doctor_Info;
import com.huazi.user.registration.tool.BaseDao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * 查看医生信息的方法
 */
public class Docator_Info_Impl extends BaseDao implements Docator_Info {
    ResultSet rs = null;

    /**
     * 根据医生科室查询医生信息
     *
     * @param type 这个是 用户传过来的科室
     * @return
     */
    @Override
    public List<Doctor_Info> findByType(String type) {
        Doctor_Info doctor_info = null;
        List<Doctor_Info> list = new ArrayList<>();
        //这是查询医生信息的sql语句
        String sql = "SELECT doctorId,doctorname,doctorSex,doctorAge,doctorke,position,type FROM `doctor_information` where `type`=?";
        rs = excuteQuery(sql, type);
        try {
            //遍历循环获得医生的值
            while (rs.next()) {
                String doctorId = rs.getString(1);
                String name = rs.getString(2);
                String sex = rs.getString(3);
                Integer age = rs.getInt(4);
                String doctorke = rs.getString(5);
                String postion = rs.getString(6);
                String types = rs.getString(7);
                //给new出来的医生对象赋值
                doctor_info = new Doctor_Info(doctorId, name, sex, age, doctorke, postion, types);
                list.add(doctor_info);
                //将医生存入list中
            }
        } catch (SQLException sqlException) {
            System.out.println("我是煞笔我不会写对不起");
        }
        return list;//返回list
    }

    /**
     * 根据医生名字查询医生信息
     *
     * @param name 姓名
     * @return
     */
    @Override
    public Doctor_Info findByName(String name) {
        Doctor_Info doctor_info = null;
        //查询医生信息的sql根据姓名
        String sql = "SELECT doctorId,doctorname,doctorSex,doctorAge,doctorke,position,type FROM `doctor_information` where `doctorname`=?";
        rs = excuteQuery(sql, name);
        try {
            while (rs.next()) {
                //获得值
                String doctorId = rs.getString(1);
                String names = rs.getString(2);
                String sex = rs.getString(3);
                Integer age = rs.getInt(4);
                String doctorke = rs.getString(5);
                String postion = rs.getString(6);
                String types = rs.getString(7);
                //返回医生
                return doctor_info = new Doctor_Info(doctorId, names, sex, age, doctorke, postion, types);
            }
        } catch (SQLException sqlException) {
            System.out.println("我是煞笔我不会写对不起");
        }
        return null;
    }
}
